#include <vector>
#include <climits>
#include <string>

using namespace std;

// LCR 008. 长度最小的子数组
class Solution1
{
public:
    int minSubArrayLen(int target, vector<int>& nums) 
    {
        int left = 0, right = 0, sum = 0, n = nums.size(), ret = INT_MAX;
        while(right < n)
        {
            sum += nums[right++];
            while(sum >= target)
            {
                sum -= nums[left++];
                ret = min(ret, right - left + 1);
            }
        }
        return ret == INT_MAX ? 0 : ret;
    }
};

// LCR 005. 最大单词长度乘积
class Solution2
{
public:
    int maxProduct(vector<string>& words) 
    {
        int n = words.size();
        vector<int> masks(n);
        for(int i = 0; i < n; ++i)
        {
            string& word = words[i];
            int len = word.size();
            for(int j = 0; j < len; ++j)
            {
                masks[i] |= 1 << (word[j] - 'a');
            }
        }

        size_t ret = 0;
        for(int i = 0; i < n; ++i)
        {
            for(int j = i + 1; j < n; ++j)
            {
                if((masks[i] & masks[j]) == 0)
                {
                    ret = max(ret, words[i].size() * words[j].size());
                }
            }
        }
        return ret;
    }
};

// 不含重复字符的最长子字符串   
class Solution3 
{
public:
    int lengthOfLongestSubstring(string s) 
    {
        int ret = 0, n = s.size(), left = 0, right = 0, hash[128]{};
        while(right < n)
        {
            char in = s[right];
            ++hash[in];
            while(hash[in] > 1)
            {
                char out = s[left++];
                --hash[out];
            }
            ret = max(ret, right - left + 1);
            ++right;
        }
        return ret;
    }
};

// 1004. 最大连续1的个数 III
class Solution4
{
public:
    int longestOnes(vector<int>& nums, int k) 
    {
        int ret = 0, left = 0, right = 0, n = nums.size(), zero = 0;
        while(right < n)
        {
            if(nums[right] == 0) ++zero;
            while(zero > k)
            {
                if(nums[left++] == 0) --zero;
            }
            ret = max(ret, right - left + 1);
            ++right;
        }
        return ret;
    }
};